const http = require('axios')
const key = 'IZ6BZ-AD7O6-XFBSY-M7BW2-IYNC3-MPBCB'

exports.getPath = async function (path) {
  try {
    const { from, to } = path
    const { status, result } = await http.get(
      `https://apis.map.qq.com/ws/direction/v1/driving/?from=${from.join(
        ','
      )}&to=${to.join(',')}&output=json&callback=cb&key=${key}`
    )

    if (status === 0) {
      const { polyline } = result.routes[0]
      return polyline
    }
    throw new Error('获取路径失败')
  } catch (error) {
    throw new Error('获取路径失败')
  }
}
